package com.trade.service.impl;


import com.trade.dao.ItemBuyBaseDAO;
import com.trade.dao.ItemSellBaseDAO;
import com.trade.domain.ItemBuyDo;
import com.trade.domain.ItemSellDo;
import com.trade.domain.ServiceResult;
import com.trade.service.UploadGoodManager;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2016/10/14.
 */
public class UploadGoodManagerImpl implements UploadGoodManager{
    @Resource
    private ItemBuyBaseDAO itemBuyBaseDAO;
    @Resource
    private ItemSellBaseDAO itemSellBaseDAO;

    public ServiceResult<List<ItemSellDo>> upload(ItemBuyDo itemBuyDo) {
        ServiceResult<List<ItemSellDo>> serviceResult = new ServiceResult<List<ItemSellDo>>();
        serviceResult.setSuccess(false);
        if (itemBuyDo == null) {
            serviceResult.setErrMsg("itemSellDo不能为空");
            return serviceResult;
        }
        //设为空，防止用户指定id
        itemBuyDo.setCommodityID(null);
        boolean result = itemBuyBaseDAO.insertItemBuy(itemBuyDo);
        if (!result) {
            serviceResult.setErrMsg("添加失败");
            return serviceResult;
        }
        //根据买家的条件查询所需商品
        List<ItemSellDo> list = itemSellBaseDAO.selectItemSellByBuy(itemBuyDo);
        serviceResult.setModel(list);
        serviceResult.setSuccess(true);
        return serviceResult;
    }

    public ServiceResult<Boolean> modify(ItemBuyDo itemBuyDo) {
        ServiceResult<Boolean> serviceResult = new ServiceResult<Boolean>();
        serviceResult.setSuccess(false);
        if (itemBuyDo == null) {
            serviceResult.setErrMsg("itemSellDo不能为空");
            return serviceResult;
        }
        boolean result = itemBuyBaseDAO.updateItemBuy(itemBuyDo);
        if (!result) {
            serviceResult.setErrMsg("修改失败");
            return serviceResult;
        }
        serviceResult.setSuccess(true);
        return serviceResult;
    }

}
